//结果码
import Message from './errorCode.json';

export class Code {
	// 成功
	public static LOGIN_SUCCESS = 10000; // 登录成功
	public static CHECK_IN_SUCCESS = 10001; //签入成功
	public static CHECK_OUT_SUCCESS = 10002; //签出成功
	public static READY_SUCCESS = 10003; //就绪成功
	public static UNREADY_SUCCESS = 10004; //未就绪成功
	public static ANSWER_SUCCESS = 10005; //接听成功
	public static RENDER_SUCCESS = 10006; // 渲染成功
	public static REJECT_SESSION_SUCCESS = 10007; // 拒绝对话成功
	public static HANG_UP_SUCCESS = 10008; // 挂断会话成功
	public static CREATE_BACKGROUND_SUCCESS = 10009; // 上传虚拟背景图片成功
	public static GET_BACKGROUND_LIST_SUCCESS = 10010; // 获取虚拟背景列表成功
	public static APPLY_BACKGROUND_SUCCESS = 10011; // 应用背景图片成功
	public static DELETE_BACKGROUND_SUCCESS = 10012; // 删除背景图片成功
	public static APPLY_OTHER_WORK_SUCCESS = 10013; // 应用小休成功
	public static CHECKED_OTHER_WORK_SUCCESS = 10014; // 查询小修成功
	public static CHECKED_CALL_PROGRESS_SUCCESS = 10015; // 查询呼叫排队数成功
	public static LOGOUT_SUCCESS = 10016; // 坐席登出成功
	public static PICTURE_IN_PICTURE_SUCCESS = 10017; // 进入画中画成功
	public static GET_WATER_MARK_LIST_SUCCESS = 10018; // 获取水印列表成功
	public static APPLY_WATER_MARK_SUCCESS = 10019; // 应用水印图片成功
	public static DELETE_WATER_MARK_SUCCESS = 10020; // 删除水印图片成功
	public static CREATE_WATER_MARK_SUCCESS = 10021; // 上传虚拟背景图片成功
	public static START_VIDEO_SUCCESS = 10022; // 启动音视频成功
	public static ACCEPT_UPGRADE_SUCCESS = 10023; // 接受升级成功
	public static REQUEST_UPGRADE_SUCCESS = 10024; // 请求升级成功
	public static AFTER_WORK_END_SUCCESS = 10025; //话后整理结束成功
	public static AFTER_WORK_START_SUCCESS = 10026; //话后整理开启成功
	public static GET_SESSION_MEMBERS_SUCCESS = 10027; //获取sessionMembers成功
	public static OBSERVER_JOIN_SESSION_SUCCESS = 10028; // 静默观战成员加入会话失败

	// 会话中事件
	public static SYSTEM_ERROR_EVENT = 20000; // 系统错误事件
	public static STREAM_ADD_EVENT = 20001; // 流加入事件
	public static STREAM_END_EVENT = 20002; // 流离开事件
	public static CCS_DROP_EVENT = 20003; // ccsDrop 事件
	public static CUSTOMER_JOIN_EVENT = 20004; // 访客加入事件
	public static CUSTOMER_QUIT_EVENT = 20005; // 访客离开事件
	public static AGENT_JOIN_EVENT = 20006; // 访客加入事件
	public static AGENT_QUIT_EVENT = 20007; // 访客离开事件
	public static ON_DROP_EVENT = 20008; // 访客离开事件
	public static AMS_CONNECT_EVENT = 20009; // ams 事件
	public static CCS_ERROR_EVENT = 20010; // ccs error 事件
	public static ON_RING_EVENT = 20011; //  振铃事件
	public static ON_CANCEL_RING_EVENT = 20012; //  取消振铃事件
	public static PUBLISH_MEDIA_STATUS_EVENT = 20013; //  流发布状态事件
	public static RENDER_MEDIA_STATUS_EVENT = 20014; //  渲染流状态事件
	public static OTHER_RECONNECTING_EVENT = 20015; //  其他用户重连事件
	public static OTHER_RESUME_RECONNECT_EVENT = 20016; // 其他用户已重连
	public static SESSION_CONNECT_STATUS_EVENT = 20017; // 会话状态
	public static TEXT_MESSAGE_EVENT = 20018; // 文本消息事件
	public static RESOURCE_MESSAGE_EVENT = 20019; // 资源消息事件
	public static CUSTOMIZE_MESSAGE_EVENT = 20020; // 自定义消息事件
	public static INVITATION_PROGRESS_EVENT = 20021; // 邀请进度事件
	public static VARIABLE_CHANGE_EVENT = 20022; // 邀请进度事件
	public static SET_AGENT_STATUS_EVENT = 20023; //设置坐席状态事件
	public static ON_RESET_STATUS_EVENT = 20024; //设置坐席状态事件
	public static PAGE_LEAVE_EVENT = 20025; // 查询呼叫排队数失败
	public static SYNC_MESSAGE_EVENT = 20026; //业务指令 发送 收到 事件

	public static REAL_TIME_QUALITY_EVENT = 20027; //监听实时质检结果返回
	public static ON_UPGRADE_EVENT = 20028; //  升降级事件

	public static UPDATE_CLIENT_INFO = 20029;

	public static CUSTOMER_VIEW_MARK_EVENT = 20030; // 实时标注

	public static DOM_EVENT = 29999; // DMO 元素事件

	public static RECORDING_ALERT_EVENT = 30000;

	public static ON_CCS_RESUME_SUCCESS_EVENT = 20089;

	public static ON_SESSION_RECORD_CRASH_EVENT = 20090;

	public static ON_SYSTEM_RECORD_UPDATE_EVENT = 20091;
	public static ON_SYNC_SESSION_SUMMARY_EVENT = 20092;
	public static ON_NEED_DO_SUMMARY_CHANGE = 20093;
	public static MODIFY_PASSWORD_EVENT = 20094;
	public static NEED_UPDATE_PASSWORD_EVENT = 20095;

	// 错误
	public static LOGIN_ERROR = 40000; //登录失败
	public static CHECK_IN_ERROR = 40001; //签入失败
	public static CHECK_OUT_ERROR = 40002; //签入失败
	public static READY_ERROR = 40003; //就绪失败
	public static UNREADY_ERROR = 40004; //未就绪成功
	public static ANSWER_ERROR = 40005; //接听失败
	public static RENDER_ERROR = 40006; // 渲染成功
	public static REJECT_SESSION_ERROR = 40007; // 拒绝对话失败
	public static HANG_UP_ERROR = 40008; // 挂断会话失败
	public static CREATE_BACKGROUND_ERROR = 40009; // 上传虚拟背景图片失败
	public static GET_BACKGROUND_LIST_ERROR = 40010; // 获取虚拟背景列表失败
	public static APPLY_BACKGROUND_ERROR = 40011; // 应用背景图片失败
	public static DELETE_BACKGROUND_ERROR = 40012; // 删除背景图片失败
	public static APPLY_OTHER_WORK_ERROR = 40013; // 应用小休失败
	public static CHECKED_OTHER_WORK_ERROR = 40014; // 查询小修失败
	public static CHECKED_CALL_PROGRESS_ERROR = 40015; // 查询呼叫排队数失败
	public static LOGOUT_ERROR = 40016; // 坐席登出失败
	public static PICTURE_IN_PICTURE_ERROR = 40017; // 进入画中画失败
	public static CREATE_WATER_MARK_ERROR = 40018; // 上传水印图片失败
	public static GET_WATER_MARK_LIST_ERROR = 40019; // 获取水印列表失败
	public static APPLY_WATER_MARK_ERROR = 40020; // 应用水印图片失败
	public static DELETE_WATER_MARK_ERROR = 40021; // 删除水印图片失败
	public static ACCEPT_UPGRADE_ERROR = 40022; // 升级失败
	public static REQUEST_UPGRADE_ERROR = 40023; // 升级请求失败
	public static REJECT_UPGRADE_ERROR = 40024; // 拒绝升级失败
	public static CANCEL_UPGRADE_ERROR = 40025; // 取消升级失败
	public static START_VIDEO_ERROR = 40026; // 启动音视频失败
	public static AFTER_WORK_END_ERROR = 40027; //话后整理结束失败
	public static AFTER_WORK_START_ERROR = 40028; //话后整理开启失败
	public static GET_SESSION_MEMBERS_ERROR = 40029; //获取sessionMembers失败
	public static OBSERVER_JOIN_SESSION_ERROR = 40030; // 静默观战成员加入会话失败

	//参数错误
	public static LOGIN_PARAMS_ERROR = 50000; //登录参数错误
	public static CHECK_IN_PARAMS_ERROR = 50001; //签入参数错误
	public static CHECK_OUT_PARAMS_ERROR = 50002; //签出参数错误
	public static READY_PARAMS_ERROR = 50003; //就绪参数错误
	public static UNREADY_PARAMS_ERROR = 50004; //未就绪参数错误
	public static ANSWER_PARAMS_ERROR = 50005; //接听参数错误
	public static RENDER_PARAMS_ERROR = 50006; // 渲染成功
	public static REJECT_SESSION_PARAMS_ERROR = 50007; // 拒绝对话参数错误
	public static HANG_UP_PARAMS_ERROR = 50008; // 挂断会话参数错误
	public static CREATE_BACKGROUND_PARAMS_ERROR = 50009; // 上传虚拟背景图片失败
	public static CREATE_BACKGROUND_COUNT_ERROR = 50010; // 上传虚拟背景已超最大限制
	public static GET_BACKGROUND_LIST_PARAMS_ERROR = 50011; // 获取虚拟背景列表参数错误
	public static APPLY_BACKGROUND_PARAMS_ERROR = 50012; // 应用背景图片失败,参数错误
	public static DELETE_BACKGROUND_PARAMS_ERROR = 50013; // 删除背景图片失败, 参数错误
	public static APPLY_OTHER_WORK_PARAMS_ERROR = 50014; // 应用小休失败
	public static CHECKED_OTHER_WORK_PARAMS_ERROR = 50015; // 查询小修失败, 参数错误
	public static CHECKED_CALL_PROGRESS_PARAMS_ERROR = 50016; // 查询呼叫排队数失败, 参数错误
	public static CREATE_WATER_MARK_PARAMS_ERROR = 50017; // 上传水印图片失败
	public static CREATE_WATER_MARK_COUNT_ERROR = 50018; // 上传水印已超最大限制
	public static GET_WATER_MARK_LIST_PARAMS_ERROR = 50019; // 获取水印列表参数错误
	public static APPLY_WATER_MARK_PARAMS_ERROR = 50020; // 应用水印图片失败,参数错误
	public static DELETE_WATER_MARK_PARAMS_ERROR = 50021; // 删除背景图片失败, 参数错误

	// API 错误
	public static READY_ERROR_AMS_EXCEPTION = 60000; //就绪失败,AMS 异常
	public static READY_ERROR_SESSION_EXCEPTION = 60001; //就绪失败, 会话 异常
	public static UNREADY_ERROR_AMS_EXCEPTION = 60002; //未就绪失败,AMS 异常
	public static UNREADY_ERROR_SESSION_EXCEPTION = 60003; //未就绪失败, 会话 异常
	public static ANSWER_ERROR_AMS_EXCEPTION = 60004; //接听失败, AMS 异常
	public static ANSWER_ERROR_SESSION_EXCEPTION = 60005; //接听失败, 会话 异常
	public static RENDER_ERROR_AMS_EXCEPTION = 60006; //渲染失败, AMS 异常
	public static RENDER_ERROR_SESSION_EXCEPTION = 60007; //渲染失败, 会话 异常
	public static REJECT_SESSION_AMS_ERROR = 60008; // 拒绝对话失败, AMS 异常
	public static REJECT_SESSION_THE_SESSION_ERROR = 60009; // 拒绝对话失败, 会话 异常
	public static HANG_UP_AMS_ERROR = 60010; // 挂断会话 AMS 异常
	public static HANG_UP_SESSION_ERROR = 60011; // 挂断会话 AMS 异常
	public static CREATE_BACKGROUND_API_ERROR = 60012; // 上传虚拟背景图片失败,接口错误
	public static GET_BACKGROUND_LIST_API_ERROR = 60013; // 获取虚拟背景列表接口错误
	public static APPLY_BACKGROUND_AMS_ERROR = 60014; // 应用背景图片失败,AMS 异常
	public static APPLY_BACKGROUND_SESSION_ERROR = 60015; // 应用背景图片失败, 会话 异常
	public static APPLY_BACKGROUND_API_ERROR = 60016; // 应用背景图片失败, api 异常
	public static DELETE_BACKGROUND_API_ERROR = 60017; // 删除背景图片失败, api 异常
	public static APPLY_OTHER_WORK_AMS_ERROR = 60018; // 应用小休失败 ams 异常
	public static APPLY_OTHER_WORK_SESSION_ERROR = 60019; // 应用小休失败 会话 异常
	public static CHECKED_OTHER_WORK_API_ERROR = 60020; // 查询小修失败, api 异常
	public static CHECKED_CALL_PROGRESS_AMS_ERROR = 60021; // 查询呼叫排队数失败, ams 异常
	public static CHECKED_CALL_PROGRESS_SESSION_ERROR = 60022; // 查询呼叫排队数失败, 会话 异常
	public static CHECKED_CALL_PROGRESS_API_ERROR = 60023; // 查询呼叫排队数失败, api 异常

	// 校验错误
	public static FILE_SIZE_ERROR = 70000; // 文件大小错误
	public static FILE_TYPE_ERROR = 70001; // 文件类型错误
	public static IMAGE_SIZE_ERROR = 70002; // 图片尺寸错误

	//业务错误
	public static UNKNOWN_ERROR = 99999; //未知错误
}

class Response extends Code {
	private static message: string;
	private static status: Status;
	private static type: EevntType;
	private static data: object | null;
	constructor() {
		super();
		Response.message = '';
		Response.status = Status.UNKNOWN;
		Response.type = EevntType.INIT;
		Response.data = null;
	}
	public static creteResponseWithCode(code: number, data: object | null) {
		return { code, message: Response.setResponseMessage(code), status: Response.setResponseStatus(code), type: Response.setResponseType(code), data: Response.setResponseData(data) };
	}

	private static setResponseStatus(code: number) {
		this.status = code < 40000 ? Status.SUCCESS : code === Code.UNKNOWN_ERROR ? Status.UNKNOWN : Status.ERROR;
		return this.status;
	}

	private static setResponseMessage(code: number) {
		this.message = Message[code];
		return this.message;
	}

	private static setResponseData(data: object | null) {
		this.data = data;
		return this.data;
	}
	private static setResponseType(code: number) {
		let type = EevntType.INIT;
		switch (code) {
			case Code.LOGIN_SUCCESS:
				type = EevntType.INIT;
				break;

			default:
				break;
		}
		this.type = type;
		return this.type;
	}
}

export enum Status {
	SUCCESS = 'success',
	ERROR = 'error',
	UNKNOWN = 'unknown'
}

export enum EevntType {
	INIT = 'init', // 初始化
	API = 'api', // 接口
	PARAMS = 'params', // 参数
	UPDATE = 'update', // 更新
	ADD = 'add', // 添加
	DELETE = 'delete', // 删除
	APPLY = 'apply' // 应用
}

export default Response;
